package online

import (
	"server/common"

	"github.com/mitchellh/mapstructure"
	"github.com/sirupsen/logrus"
)

// -------------------------------------------------------------------------------------------------
//
// -------------------------------------------------------------------------------------------------
func (s *OnlineService) handleStartPublishAck(msg common.Message, from common.ServiceInfo,
	connId string) error {
	common.Logger(common.SERVICE_TYPE_ONLINE, msg.Rid).WithFields(logrus.Fields{
		"msg":    common.ToJson(msg),
		"from":   from,
		"connId": connId,
	}).Info("call handleStartPublishAck")

	var res common.ResMessage
	if err := mapstructure.Decode(msg.Data, &res); err != nil {
		errStr := "invalid start publish ack data format: " + err.Error()
		common.Logger(common.SERVICE_TYPE_ONLINE, msg.Rid).WithError(err).Error(errStr)
		return nil
	}

	if res.Data.Code != 0 {
		common.Logger(common.SERVICE_TYPE_ONLINE, msg.Rid).Error("start publish ack failed")
	} else {
		common.Logger(common.SERVICE_TYPE_ONLINE, msg.Rid).Info("start publish ack success")
	}

	return nil
}
